package com.qf.xiaomi.web.servlet;

import com.qf.xiaomi.pojo.TbGoods;
import com.qf.xiaomi.pojo.pageBean;
import com.qf.xiaomi.service.GoodsService;
import com.qf.xiaomi.service.impl.GoodsServiceImpl;
import com.qf.xiaomi.utils.StringConstans;
import com.qf.xiaomi.web.base.BaseServlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/product")
public class ProductServlet extends BaseServlet {
    GoodsService service=new GoodsServiceImpl();
    public String show(HttpServletRequest req, HttpServletResponse resp){
        String idStr = req.getParameter("id");
        long id = Long.parseLong(idStr);
//        List<TbGoods> tbGoods = service.selectByGoodsId(id);
        int currentPage=1;
        String currentPageStr=req.getParameter("currentPage");
        if(currentPageStr!=null){
            currentPage=Integer.parseInt(currentPageStr);
        }
    int pageSize = 3;
        String pageSizeStr = req.getParameter("pageSize");
        if (pageSizeStr!=null){
            pageSize=Integer.parseInt(pageSizeStr);
        }
        pageBean page = new pageBean();
        page.setCurrentPage(currentPage);
        page.setPageSize(pageSize);
        pageBean pageBean = service.selectPage(id, page);
        req.setAttribute("pageBean",pageBean);
        return StringConstans.FORWARD +"/goodsList.jsp";
    }
    public String detail(HttpServletRequest req, HttpServletResponse resp){
        String GoodsIdStr = req.getParameter("id");
        long GoodId = Long.parseLong(GoodsIdStr);
        TbGoods tbGoodsKz = service.selectByGoodId(GoodId);
        req.setAttribute("product",tbGoodsKz);
        return StringConstans.FORWARD +"/goodsDetail.jsp";
    }
}
